package com.cug.nageoffer.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cug.nageoffer.model.entity.OnlineResume;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.cug.nageoffer.user.mapper.OnlineResumeMapper;
import com.cug.nageoffer.user.service.OnlineResumeService;
import com.cug.nageoffer.util.AuthContextUtil;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class OnlineResumeServiceImpl extends ServiceImpl<OnlineResumeMapper, OnlineResume> implements OnlineResumeService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void modify(OnlineResume requestParam) {
        OnlineResume onlineResume = query().eq("user_id", AuthContextUtil.get().getId()).one();
        if(onlineResume == null){
            requestParam.setUserId(AuthContextUtil.get().getId());
            save(requestParam);
            return;
        }
        update().eq("user_id",AuthContextUtil.get().getId()).update(requestParam);
    }

    @Override
    public Result<OnlineResume> search(Long userId) {
        OnlineResume onlineResume = query().eq("user_id", userId).one();
        if(onlineResume==null){
            return Result.build(null, ResultCodeEnum.SUCCESS);
        }
        return Result.build(onlineResume,ResultCodeEnum.SUCCESS);
    }
}
